import VueRouter from 'vue-router'

//导入对应的路由组件
import HomeContainer from './components/tabbar/HomeContainer.vue'
import MemberContainer from './components/tabbar/MemberContainer.vue'
import DeleteContainer from './components/tabbar/DeleteContainer.vue'
import ManageContainer from './components/tabbar/ManageContainer.vue'
import DataContainer from './components/tabbar/DataContainer.vue'
import ShopcartContainer from './components/tabbar/ShopcartContainer.vue'
import Goodslist from './components/goods/goodslist.vue'
import GoodsInfo from './components/goods/goodsinfo.vue'
import GoodsDesc from './components/goods/goodsdesc.vue'
import Login from './components/login.vue'
import TicketContainer from './components/tabbar/TicketContainer.vue'
import Register from './components/register.vue'
import GoodsComment from './components/goods/goodscomment.vue'

var router = new VueRouter({
    routes:[        //配置路由规则
        { path:'/', redirect: '/login'},
        { path:'/login', component: Login},
        { path:'/register', component: Register},
        { path:'/home', component: HomeContainer},
        { path:'/member', component: MemberContainer},
        { path:'/delete', component: DeleteContainer},
        { path:'/manage', component: ManageContainer},
        { path:'/data', component: DataContainer},
        { path:'/shopcart', component: ShopcartContainer},
        { path:'/ticket', component: TicketContainer},
        { path:'/home/goodslist', component: Goodslist},
        { path:'/home/goodsinfo/:id', component: GoodsInfo, name: 'goodsinfo' },
        { path:'/home/goodsdesc/:id', component: GoodsDesc, name: 'goodsdesc' },
        { path:'/home/goodscomment/:id', component: GoodsComment, name: 'goodscomment' },
    ],
    linkActiveClass:'mui-active'    //覆盖默认高亮的类 默认的类叫做router-link-active
});

// 路由守护
router.beforeEach((to, from, next) => {
    const isLogin = sessionStorage.token ? true : false;
    if(to.path == '/login' || to.path == '/register'){
        next();
    }else {
        isLogin ? next() : next('/login');
    }
});

//把路由对象暴露出去
export default router
